<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/10/13
 * Time: 22:07
 */
namespace app\model;


use think\facade\Db;
use think\Model;

class Wx extends Model
{
    protected $table = 'user_wx';

    public function addOneWx($data)
    {
        $data['wx_create_time'] = time();
        return Db::table('user_wx')->insertGetId($data);
    }


    public function getWxInfByOpenid($openid,$field = "*")
    {
        return Db::table('user_wx')->where(['wx_openid'=>$openid])->field($field)->find();

    }

    public function updateWxInfoByWhere($where,$data)
    {
        $data['wx_update_time'] = time();
        return Db::table('user_wx')->where($where)->update($data);

    }


    public function getAccessToken($appid = '')
    {
        $appid = $appid ? $appid : config('wx.appId');
        return Db::table('wx_access_token')->where(['wt_appid'=>$appid])->find();
    }

    public function updateAccessToken($appid = '',$data)
    {
        $appid = $appid ? $appid : config('wx.appId');
        $data['wt_update_time'] = time();
        return Db::table('wx_access_token')->where(['wt_appid'=>$appid])->update($data);
    }


}